<template>
    Category
</template>

<script setup>
import { onMounted, ref } from 'vue';

import { getCategoryList } from '../api';


const menus = ref([])

onMounted(() => {
    loadCategoryList()
})

const loadCategoryList = async () => {
    let data =await getCategoryList()
    const treeData = convertToTree(data)

}
const convertToTree = data => {
    const treeData = []
    const map = []

    for (const item of data) {
        map[item.id] = {...item,children:[]}
    }
    for(const item of data) {
        const node = map[item.id]
        if(item.pid === 0) {
            treeData.push(node)
        } else {
            const parent = map[item.id]
            parent.children.push(node)
        }
    }
    return treeData
}


</script>